public class Solution955 {
    public int minDeletionSize(String[] strs) {
        int ans=0;
        while (true){
            boolean flag=true;
            for (int i=0;i<strs.length-1;i++){
                if (strs[i].compareTo(strs[i+1])>0){
                    ans++;
                    int target=-1;
                    for (int j=0;j<strs[i].length();j++){
                        if (strs[i].charAt(j)!=strs[i+1].charAt(j)){
                            target=j;
                            break;
                        }
                    }
                    for (int j=0;j<strs.length;j++){
                        strs[j]=strs[j].substring(0,target).concat(strs[j].substring(target+1));
                    }
                    flag=false;
                    break;
                }
            }
            if (flag){
                break;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution955().minDeletionSize(new String[]{"zyx","wvu","tsr"}));
    }
}
